<?php

/**
 * This is the model class for table "xman_task_list".
 *
 * The followings are the available columns in table 'xman_task_list':
 * @property integer $task_list_id
 * @property string $task_list_name
 * @property integer $tasklist_project_id
 * @property string $task_list_description
 *
 * The followings are the available model relations:
 * @property Task[] $tasks
 * @property Project $tasklistProject
 */
class TaskList extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return TaskList the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_task_list';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('task_list_name, tasklist_project_id', 'required'),
			array('tasklist_project_id', 'numerical', 'integerOnly'=>true),
			array('task_list_name', 'length', 'max'=>50),
			array('task_list_description', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('task_list_id, task_list_name, tasklist_project_id, task_list_description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tasks' => array(self::HAS_MANY, 'Task', 'task_task_list_id'),
			'tasklistProject' => array(self::BELONGS_TO, 'Project', 'tasklist_project_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'task_list_id' => 'Task List',
			'task_list_name' => 'Task List Name',
			'tasklist_project_id' => 'Tasklist Project',
			'task_list_description' => 'Task List Description',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('task_list_id',$this->task_list_id);
		$criteria->compare('task_list_name',$this->task_list_name,true);
		$criteria->compare('tasklist_project_id',$this->tasklist_project_id);
		$criteria->compare('task_list_description',$this->task_list_description,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}